package File;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class LianXi02 {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入文件名");
        String input = scanner.nextLine().trim();
        File file = new File("test.txt");
        boolean flag = file.exists();
        if (!flag) {
            file.createNewFile();
        } else {
            System.out.println("该目录已存在");
            int index = 0;
            while (flag) {
                index++;
                file = new File("test_副本"+ index +".txt");
                flag = file.exists();
            }
            file.createNewFile();
        }
        System.out.println("文件名:" + file.getName());
    }
}
